home *** CD-ROM | disk | FTP | other *** search
/ Hyper Stacks 1994 May / Hyper Stacks (Pacific HiTech)(1994)[Mac].iso / HyperTalk / HyperCard Dev. Toolkit / XCMD.Sources / openPort.p < prev    next >
Encoding:
Text File  |  1987-08-17  |  1.9 KB  |  86 lines  |  [TEXT/MPS ]

  1. {$R-}
  2.  
  3. (*
  4.     openSPort portNumber -- Open the serial port driver.
  5.     By Harry Chesley.  DO NOT call the author!  Contact Apple Developer 
  6.     Support on AppleLink "MacDTS" or on MCI "MacTech".
  7.  
  8.     ©Apple Computer, Inc. 1987
  9.     All Rights Reserved.
  10.  
  11.     To compile and link this file using Macintosh Programmer's Workshop,
  12.  
  13.     pascal -w openPort.p
  14.     link -m ENTRYPOINT -o HyperTerm -rt XCMD=0 -sn Main=openSPort openPort.p.o "{MPW}"Libraries:interface.o
  15.     
  16. *)
  17.  
  18. {$S openSPort }     { Segment name must be the same as the command name. }
  19.  
  20. unit DummyUnit;
  21.  
  22. interface
  23.  
  24. uses MemTypes, QuickDraw, OSIntf, HyperXCmd;
  25.  
  26. procedure EntryPoint(paramPtr: XCmdPtr);
  27.     
  28. implementation
  29.  
  30. type
  31.  
  32. Str31 = String[31];
  33.  
  34. procedure openSPort(paramPtr: XCmdPtr); forward;
  35.  
  36. procedure EntryPoint(paramPtr: XCmdPtr);
  37.  
  38.     begin
  39.         openSPort(paramPtr);
  40.     end;
  41.  
  42. procedure openSPort(paramPtr: XCmdPtr);
  43.  
  44.     var portNumber: integer;    
  45.         inPort, outPort: integer;
  46.         actualIn, actualOut: integer;
  47.         i: integer;
  48.         str: Str255;
  49.         shakes: SerShk;
  50.  
  51.     {$I XCmdGlue.inc}
  52.  
  53.     procedure Fail(errMsg: Str255); { set theResult and quit }
  54.         begin
  55.             paramPtr^.returnValue := PasToZero(errMsg);
  56.             exit(openSPort);
  57.         end;
  58.  
  59.     begin
  60.         if paramPtr^.paramCount <> 1 then Fail('parameter count is not 1');
  61.  
  62.         ZeroToPas(paramPtr^.params[1]^,str);        { First parameter is port number. }
  63.         portNumber := StrToNum(str);
  64.         if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');
  65.  
  66.         if portNumber = 1 then
  67.             begin
  68.                 inPort := -6; outPort := -7;
  69.             end
  70.         else
  71.             begin
  72.                 inPort := -8; outPort := -9;
  73.             end;
  74.         if (OpenDriver('.AOut',actualOut) <> noErr) or (OpenDriver('.AIn',actualIn) <> noErr) then
  75.             Fail('OpenDriver failed');
  76.         if (actualOut <> outPort) or (actualIn <> inPort) then Fail('openDriver failed');
  77.         with shakes do
  78.             begin
  79.                 fXOn := 0; fCTS := 0; errs := 0; evts := 0; fInX := 0;
  80.             end;
  81.         if SerHShake(inPort,shakes) <> noErr then Fail('SerHShake failed');
  82.         if SerHShake(outPort,shakes) <> noErr then Fail('SerHShake failed');
  83.     end;
  84.  
  85. end.
  86.